//
//  MyButton.m
//  MvcTest
//
//  Created by SDMac on 15/5/12.
//  Copyright (c) 2015年 SDMac. All rights reserved.
//

#import "MyButton.h"

@implementation MyButton

+ (id)buttonWithType:(UIButtonType)buttonType frame:(CGRect)fram
               title:(NSString*)title
             handler:(tapHandler)handler
{
    MyButton *btn = [super buttonWithType:buttonType];
    btn.frame = fram;
    btn.titleLabel.textAlignment = NSTextAlignmentLeft;
    btn.titleLabel.font = [UIFont systemFontOfSize:18];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.handler = handler;
    [btn addTarget:btn action:@selector(getAction:) forControlEvents:UIControlEventTouchUpInside];

    return btn;
}

-(void)getAction:(UIButton*)sender
{
    tapHandler block = self.handler;
    
    // block现在是本地不可变的,如果block不等于nil
    if (block)
    {
        self.handler(sender);
    }
}

@end
